<template>
  <div class="report">
    <Breadcrumb name1="数据统计" name2="数据报表" />
    <!--  卡片-->
    <el-card>
      <!-- 2. 为ECharts准备一个具备大小（宽高）的Dom -->
      <div id="main" style="width: 950px;height:500px;"></div>
    </el-card>
  </div>
</template>

<script>
// 1. 引入 echarts 按需引入
import * as echarts from 'echarts'
import _ from 'lodash'
import Breadcrumb from 'components/content/breadcrumb/Breadcrumb'
export default {
  name: 'Report',
  components: { Breadcrumb },
  data() {
    return {
      // 需要合并的数据
      option : {
        title: {
          text: '药品销售统计图'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          data: ['退烧类药物', '消炎类药物', '防疫类物资', '长期用药', '其他']
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '退烧类药物',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '消炎类药物',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: '防疫类物资',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [150, 232, 201, 154, 390, 330, 410]
          },
          {
            name: '长期用药',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [320, 332, 301, 334, 190, 330, 320]
          },
          {
            name: '其他',
            type: 'line',
            stack: 'Total',
            label: {
              show: true,
              position: 'top'
            },
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      }
    }
  },
  // 此时,页面上的元素,已经被渲染完毕了
  // async
  mounted() {
    this.$message.success('获取折线图数据成功!')
    // 3. 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'))
    //
    // const { data: res } =
    //   await this.$http.get('http://43.143.0.76:8889/api/private/v1/reports/type/1')
    // if (res.meta.status !== 200) {
    //   return this.$message.error('获取折线图数据失败!')
    // }
    // // 4. 指定图表的配置项和数据
    // const result = _.merge(res.data, this.options)
    // // 5. 使用刚指定的配置项和数据显示图表。
    myChart.setOption(this.option)
  }
}
</script>

<style scoped></style>
